﻿@model Sniper.Admin.Framework.Datatable.DataSourceResult<Sniper.Entities.SysUser>
@{
    var arg = Model.SearchArg as Sniper.Mapping.SysUser.SysUserSearchArg;
    ViewBag.Title = "系统用户列表";
}
<div class="breadcrumbs" id="breadcrumbs">
    <ul class="breadcrumb">
        <li>
            <i class="ace-icon fa fa-home home-icon"></i>
            <a href="@Url.RouteUrl("homeIndex")">首页</a>
        </li>
        <li class="active">@ViewBag.Title</li>
    </ul>
</div>
<div class="page-content">
    <h1>@ViewBag.Title</h1>
    <hr />
    <div class="row">
        <div class="col-sm-12">
            @PermissionRouteLinkIcon("添加系统用户", "editUser", new RouteValueDictionary(new { returnUrl = Request.RawUrl }), new { @class = "btn btn-sm btn-pink " }, new { @class = "glyphicon glyphicon-plus" })
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12">
            <div class="panel panel-default">
                <div class="panel-body">
                    @using (Html.BeginRouteForm("userIndex", new { }, FormMethod.Get, new { @class = "form-inline" }))
                    {
                        <label>关键字</label>
                        <input type="text" class="form-control" style="width:220px;" placeholder="账号、姓名、邮箱、手机号">
                        <label>操作员</label>
                        @Html.Action("ChosenUser", "Widget", new { id = arg.suid })
                        <label>角色</label>
                        @Html.Action("SelectRole", "Widget", new { id = arg.roleId })
                        <button type="submit" class="btn btn-purple btn-sm">
                            查询
                            <i class="ace-icon fa fa-search icon-on-right bigger-110"></i>
                        </button>
                    }
                </div>
            </div>
        </div>
    </div>

    @if (Model != null && Model.Data != null)
    {
        <div class="row">
            <div class="col-sm-12">
                <table id="user_datatable" class="table table-striped table-bordered table-hover dataTable no-footer">
                    <thead>
                        <tr>
                            <th width="150px">账号</th>
                            <th width="100px">姓名</th>
                            <th width="110px">手机号</th>
                            <th width="60px">性别</th>
                            <th width="150px">活动时间</th>
                            <th width="100px">启用</th>
                            <th width="120px">登录锁</th>
                            <th width="50px;">密码</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model.Data)
                        {
                            <tr>
                                <td>@item.Account</td>
                                <td>@item.Name</td>
                                <td>@item.MobilePhone</td>
                                <td>@item.Sex</td>
                                <td>@(item.LastActivityTime?.ToString("MM:dd HH;mm:ss"))</td>
                                <td>
                                    @if (!item.IsAdmin)
                                    {
                                        if (item.Enabled)
                                        {
                                            <label>
                                                <input name="enabled" class="ace ace-switch ace-switch-7 user_enabled" value="@item.Id" type="checkbox" checked="checked">
                                                <span class="lbl"></span>
                                            </label>
                                        }
                                        else
                                        {
                                            <label>
                                                <input name="enabled" class="ace ace-switch ace-switch-7 user_enabled" value="@item.Id" type="checkbox">
                                                <span class="lbl"></span>
                                            </label>
                                        }
                                    }
                                </td>
                                <td>
                                    @if (item.LoginLock)
                                    {
                                        <label>
                                            <input name="lock" value="@item.Id" class="ace ace-switch ace-switch-5 user_lock" type="checkbox" checked="checked">
                                            <span class="lbl"></span>
                                        </label>
                                        if (item.AllowLoginTime.HasValue && item.AllowLoginTime > DateTime.Now)
                                        {
                                            <span class="badge">@((int)(item.AllowLoginTime.Value - DateTime.Now).TotalMinutes + 1)分</span>
                                        }
                                    }
                                    else
                                    {
                                        <label data-toggle="tooltip" data-placement="left" title="Tooltip on left">
                                            <input name="lock" value="@item.Id" class="ace ace-switch ace-switch-5 user_lock" type="checkbox">
                                            <span class="lbl"></span>
                                        </label>
                                    }
                                </td>
                                <td>
                                    @if (!item.IsAdmin)
                                {
                                    @PermissionRouteLinkIcon("", "resetPassword", new RouteValueDictionary(new { id = item.Id }), new { @class = "btn btn-xs btn-warning btnResetPwd", title = "重置密码" }, new { @class = "ace-icon fa fa-undo" })
                                }
                            </td>
                            <td>
                                @PermissionRouteLinkIcon("", "editUser", new RouteValueDictionary(new { id = item.Id, returnUrl = Request.RawUrl }), new { @class = "btn btn-xs btn-info", title = "修改资料" }, new { @class = "glyphicon glyphicon-pencil" })
                                @if (!item.IsAdmin)
                                {
                                    @PermissionRouteLinkIcon("角色", "editUserRole", new RouteValueDictionary(new { id = item.Id, returnUrl = Request.RawUrl }), new { @class = "btn btn-xs btn-grey", title = "设置角色" }, new { @class = "glyphicon glyphicon-user" })
                                }
                                @if (!item.IsAdmin)
                                {
                                    @PermissionRouteLinkIcon("", "deleteUser", new RouteValueDictionary(new { id = item.Id }), new { @class = "btn btn-xs btn-danger btnDelete", title = "删除用户" }, new { @class = "glyphicon glyphicon-trash" })
                                }
                            </td>
                        </tr>
                        }
                    </tbody>
                </table>
                @Pagination(Model.Paging)
            </div>
        </div>
        @Html.AntiForgeryToken()
        <script>
            $(function () {
                $('.user_lock').on('click', function () {
                    //锁定与解锁
                    $.post('@Url.RouteUrl("loginLock")', { id: $(this).val(), loginLock: this.checked, __RequestVerificationToken: $('[name="__RequestVerificationToken"]').val() }, function (data) {
                        $.modal.gritter(data);
                    });
                });
                $('.user_enabled').click(function () {
                    //启用冻结
                    $.post('@Url.RouteUrl("enabled")', { id: $(this).val(), enabled: this.checked, __RequestVerificationToken: $('[name="__RequestVerificationToken"]').val() }, function (data) {
                        $.modal.gritter(data);
                    });
                });

                $(".btnDelete").click(function (e) {
                    e.preventDefault();
                    var url = $(this).attr('href');
                    $.modal.confirm('删除后将不可恢复，您确定要删除此用户？', function () {
                        $.get(url, function (data) {
                            $.modal.alert(data);
                        });
                    });
                });
                $('.btnResetPwd').click(function (e) {
                    e.preventDefault();
                    var url = $(this).attr('href');
                    $.modal.confirm('您确定要重置次用户密码？', function () {
                        $.get(url, function (data) {
                            $.modal.gritter(data);
                        });
                    });
                });

            });
        </script>
    }
</div>